#include "solution/utils/hardware_info.h"

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/process/launch.h"

bool HardwareInfo::GetAllInfo(std::string* info) {
  bool result = false;

  base::CommandLine cl(base::FilePath(FILE_PATH_LITERAL("system_profiler")));
  cl.AppendArg("-json");
  cl.AppendArg("SPStorageDataType");

  std::string output;
  int exit_code;

  do {
    if (!base::GetAppOutputWithExitCode(cl, &output, &exit_code)) {
      LOG(INFO) << "GetAppOutputWithExitCode failed";
      break;
    }

    if (0 != exit_code) {
      LOG(INFO) << "exit_code: " << exit_code;
      break;
    }

    if (output.empty()) {
      LOG(INFO) << "output is empty";
      break;
    }

    if (info) {
      *info = std::move(output);
    }

    LOG(INFO) << "output: " << output;

    result = true;
  } while (0);
  return result;
}
